package com.djy.shxt.nemt.service;

import com.alibaba.fastjson.JSON;
import com.djy.shxt.nemt.mapper.ISystemUserMapper;
import org.apache.commons.lang3.ObjectUtils;
import org.minbox.framework.api.boot.plugin.security.delegate.ApiBootStoreDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class SystemUserService implements ApiBootStoreDelegate {
    /**
     * logger instance
     */
    static Logger logger = LoggerFactory.getLogger(SystemUserService.class);
    /**
     * 用户数据接口
     */
    @Autowired
    private ISystemUserMapper mapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDetails userDetails = mapper.findByLoginName(username);
        if (ObjectUtils.isEmpty(userDetails)) {
            throw new UsernameNotFoundException("用户：" + username + "，不存在.");
        }
        logger.info("登录用户的信息：{}", JSON.toJSONString(userDetails));
        return userDetails;
    }
}
